<include file="public:header" />
<!--菜单添加-->
<ul id="mytab" class="nav nav-tabs" style="margin-top: 15px;">
    <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li>
    <li class="active"><a href="#con1" data-toggle="tab">新地区</a></li>
    <!--<li><a href="#con2" data-toggle="tab">菜单添加1</a></li>-->
</ul>
<div id="tabContent" class="tab-content">
    <div class="tab-pane fade in active" id="con1">
        <div style="margin-top: 20px;">
            <form class="form-horizontal" role="form" action="{:u('superadmin/area/edit')}" method="post">

                <div class="form-group">
                    <label class="col-sm-1 control-label label-form">父级分类:</label>
                    <div >

                        <select class="select_area">
                            <option value="0">--请选择--</option>
                            <volist name ="area" id="vo">
                                <option value="{$vo.id}">{$vo.name}</option>
                            </volist>
                        </select>

                        <input type="hidden" value="" id="pid" name="pid">
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-sm-1 control-label label-form">地区名称:</label>
                    <div class="col-sm-3 input-padding">
                        <input type="text" class="form-control" value="{$area.name}" name="name" id="name"
                               placeholder="请输入地区名称">
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-sm-1 control-label label-form">简短名称:</label>
                    <div class="col-sm-3 input-padding">
                        <input type="text" class="form-control" value="{$area.short_name}" name="short_name" id="short_name"
                               placeholder="请输入简短名称">
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-sm-1 control-label label-form">排序:</label>
                    <div class="col-sm-3 input-padding">
                        <input type="text" class="form-control" value="{$area.ordid}" name="ordid" id="ordid"
                               placeholder="请输入排序">
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-sm-1 control-label label-form">状态:</label>
                    <label class="checkbox-inline">
                        <input type="radio" name="status"  value="1" <if condition="$area.status eq 1"> checked="checked" </if>> 是
                    </label>
                    <label class="checkbox-inline">
                        <input type="radio" name="status" value="0" <if condition="$area.status eq 0"> checked="checked" </if>> 否
                    </label>
                </div>

                <div class="form-group">
                    <button id="save" class="btn btn-primary btn-position">保存</button>
                </div>
                <input type="hidden" value="{$area.id}" name="id">
            </form>

        </div>
    </div>
</div>


<include file="public:footer" />
<script>
$(document).ready(function(){
    $('#mytab a').click(function (e) {
        e.preventDefault()
        $(this).tab('show')
    })

    $('#save').click(function(){
        var name     = $.trim($('#name').val());
        if(!name)
        {
            $('#name').val('').focus();
            layer.tips('请输入地区名称', '#name', {
                tips: [2, '#009f95'],
                time: 2000
            });
            return false;
        }

        //数据验证
        $.ajax({
            type: "POST",
            url: $('.form-horizontal').attr('action'),
            data: $('.form-horizontal').serialize(),
            dataType: "json",
            success:function(data){
                if(data.status)
                {
                    layer.msg(data.msg,{icon: 1,time:2000, shade: [0.1, '#ccc']},function(){
                        window.location.href="{:u('superadmin/area/index')}";
                    })
                } else {
                    layer.msg(data.msg,{icon: 2,time:2000, shade: [0.1, '#ccc']})
                }

            }
        });
        return false;
    });


    //区域选择
    $(document).on('change','.select_area',function(){
        var obj = $(this);
        var pid = $(this).val();
        if(pid == 'null' || pid == '0')
        {
            obj.nextAll('.select_area').remove();
            return false;
        }
        var url = "{:U('superadmin/area/children')}"
        $.post(url,{id:pid},function(res){
            if(res.status)
            {
                var hasone = obj.nextAll('.select_area').length;
                var str = '<select class="select_area">'
                    str+= '<option value="null">--请选择--</option>'
                $.each(res.data, function(index,item){
                    str+= '<option value="'+item.id+'">'+item.name+'</option>'
                })
                str += '</select>'
                if(hasone >= 1)
                {
                    obj.nextAll('.select_area').remove();
                }
                obj.after(str);
                $('#pid').val(pid);
            }
        }, 'json')

    });


});
</script>
</body>
</html>